package org.box.demos.multithreading.wgetmt.core;

import java.io.IOException;
import java.util.Collection;
import java.util.Set;

import org.box.demos.multithreading.wgetmt.Configuration;
import org.box.demos.multithreading.wgetmt.j16mt.ProgressMonitor;

/**
 * Describes received files' storage API.
 * 
 * @author <a href="mailto:alexander.box@gmail.com">Alexander Korobka</a>
 * 
 */
public interface Storage {

	void connect(Configuration cfg) throws IOException;
	
	void disconnect() throws IOException;
	
	/**
	 * Write a content with by the given url into the storage
	 * 
	 * @param url
	 *            - the given url
	 * @param content
	 *            - the content of which have to be stored
	 * @throws IOException
	 *             if any IO exception during storing
	 */
	void write(URL url, byte[] content)
			throws IOException;

	/**
	 * Read a content from the storage by the given url
	 * 
	 * @param url
	 *            - the url of the content that have to be read
	 * 
	 * @return the content of the file by the given url
	 * 
	 * @throws IOException
	 *             if any IO exception during storing
	 */
	String read(URL url) throws IOException;

	boolean containsUrl(URL u) throws IOException;
	
	Set<URL> addUrls(Set<URL> newUrls) throws IOException;

	Collection<URL> loadIncomplete() throws IOException;
	
	/**
	 * Convert a content of file by the given url. The goal is converting urls
	 * to the applicable to storage's format. This means that e.g. storage is
	 * File System so all urls with in the content should be converted to the
	 * File System's path format
	 * 
	 * @param url
	 *            - the url of the content that have to be converted
	 * @return true, if the content was converted successful
	 * 
	 * @throws IOException
	 *             if any IO exception during storing
	 */
	boolean convert(URL url) throws IOException;

	void convertLinks(ProgressMonitor pm) throws IOException;

}
